package org.example.mallweb.mallservice.service.serviceimpl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import org.example.mallcommon.projo.UserFollow;
import org.example.mallcommon.result.ReturnResult;
import org.example.mallcommon.vio.UserDetailPage;
import org.example.mallcommon.vio.UserDetailVio;
import org.example.mallweb.mallservice.mybatiscommon.userfollow.UserFollowMapper;
import org.example.mallweb.mallservice.service.UserFollowService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;


/**
 * @author 韩先楚
 * 用户关注业务实现类
 */
@Service
public class UserFollowServiceImpl implements UserFollowService {

    @Resource
    private UserFollowMapper userFollowMapper;




    /**
     * 关注或取关用户
     */
    @Override
    public ReturnResult<String> followOrUnfollowUser(Integer userId, Integer myid, Integer follow) {
        userFollowMapper.update(null,new UpdateWrapper<UserFollow>().set("status",follow).eq("user_id",myid).eq("followed_id",userId));
        return ReturnResult.success("操作成功");
    }

    //分页获取我的关注列表
    @Override
    public ReturnResult<UserDetailPage> getMyFollowList(Integer userId, Integer page, Integer size) {
   Page<UserDetailVio>  list =     userFollowMapper.getMyFollowsList(new Page<UserDetailVio>(page,size),userId);
        UserDetailPage userDetailPage = new UserDetailPage();
        userDetailPage.setUserDetails(list.getRecords());
        userDetailPage.setCount(list.getTotal());
        return ReturnResult.success(userDetailPage);
    }

    //分页获取我的粉丝列表
    @Override
    public ReturnResult<UserDetailPage> getMyFansList(Integer userId,Integer page, Integer size) {

        Page<UserDetailVio>  list =     userFollowMapper.getMyFansList(new Page<UserDetailVio>(page,size),userId);
        UserDetailPage userDetailPage = new UserDetailPage();
        userDetailPage.setUserDetails(list.getRecords());
        userDetailPage.setCount(list.getTotal());
        return ReturnResult.success(userDetailPage);
    }
}
